package mymyoux.utils
{
	public class Temporizer
	{
		protected var _addFunction:Function;
		protected var arguments:Array;
		protected var actived:uint;
		protected var numbers:uint;
		protected var thisObject:Object;
		public function Temporizer(addFunction:Function,thisObject:Object,numbers:uint=1)
		{
			this.numbers=numbers<1?1:numbers;
			this.thisObject=thisObject;
			_addFunction=addFunction;
			arguments=new Array();
			actived=0;
		}
		public function add(...args):void
		{
			
			if(actived<numbers)
			{
				actived++;
				_addFunction.apply(thisObject,args);
			}else
			{
				arguments.push(args);
			}
			
		}
		public function release():void
		{
			actived--;
			if(arguments.length>0)
			{
				actived++;
				_addFunction.apply(thisObject,arguments.shift());
			}
		}
	}
}